#![allow(non_snake_case)]

use std::sync::atomic::{AtomicPtr, Ordering};

mod controls;
mod globals;
mod internal;
mod rundll32;
mod service;
mod tasks;

// 全局变量存储 DLL 句柄
static G_DLL_HANDLE: AtomicPtr<std::ffi::c_void> = AtomicPtr::new(std::ptr::null_mut());

// DllMain DLL入口点
#[unsafe(no_mangle)]
#[cfg(windows)]
pub extern "system" fn DllMain(hinst: usize, reason: u32, _: *mut ()) -> bool {
    match reason {
        1 => {
            // DLL_PROCESS_ATTACH
            // 保存 DLL 句柄
            G_DLL_HANDLE.store(hinst as *mut std::ffi::c_void, Ordering::SeqCst);
            true
        } // DLL_PROCESS_ATTACH
        0 => true, // DLL_PROCESS_DETACH
        _ => true,
    }
}

#[cfg(not(windows))]
#[unsafe(no_mangle)]
pub extern "system" fn DllMain(hinst: usize, reason: u32, _: *mut ()) -> bool {
    panic!("此程序仅适用于Windows系统。");
}
